package com.levi.utils.log.printer;

import android.util.Log;

/**
 * Created by Levi on 2018/3/13.
 */
public class AndroidLogcatPrinter extends Printer {

    private static final int MAX_LOG_LENGTH = 4000;

    @Override
    public void log(int priority, String tag, final String msg) {
        if (msg.length() < MAX_LOG_LENGTH) {
            println(priority, tag, msg);
            return;
        }

        for (int i = 0, length = msg.length(); i < length; ) {
            final int end = Math.min(msg.length(), i + MAX_LOG_LENGTH);
            println(priority, tag, msg.substring(i, end));
            i = end;
        }
    }

    private void println(int priority, String tag, final String msg) {
        Log.println(priority, tag, msg);
    }
}
